package com.itheima.CSM_bacK.aabServices;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.Entity.CheckItem;
import com.itheima.pojo.DTO.DTOcItemA;
import com.itheima.pojo.DTO.DTOcItemE;
import com.itheima.pojo.VO.VOcItemFA;
import com.itheima.CSM_bacK.aabServices.Serv.CheckItemServ;
import com.itheima.CSM_bacK.aacMapper.CheckItemMapper;
import com.itheima.pojo.VO.VOcItemFBI;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class CheckItemImpl implements CheckItemServ {
    @Autowired
    private CheckItemMapper checkItemMapper;

    @Override
    public void add(DTOcItemA kk) {
        CheckItem meme = new CheckItem();
        BeanUtils.copyProperties(kk,meme);
        checkItemMapper.add(meme);
    }

    @Override
    public void delete(int id) {
        checkItemMapper.delete(id);
    }

    @Override
    public List<Integer> findCheckItemIdsByCheckGroupId(int checkgroupId) {
        return checkItemMapper.findCheckItemIdsByCheckGroupId(checkgroupId);
    }

    @Override
    public void edit(DTOcItemE kk) {
        CheckItem meme = new CheckItem();
        BeanUtils.copyProperties(kk,meme);
        checkItemMapper.edit(meme);
    }

    @Override
    public PageResult findPage(QueryPageBean kk) {
        PageHelper.startPage(kk.getCurrentPage(), kk.getPageSize());
        Page<CheckItem> kks = checkItemMapper.findPage(kk.getQueryString());

        return new PageResult(kks.getTotal(),kks.getResult());

    }
    @Override
    public List<VOcItemFA> findAll() {
        List<CheckItem> kks = checkItemMapper.findAll();
        List<VOcItemFA> vvo = new ArrayList<>();
        for (CheckItem iitem : kks) {
            VOcItemFA vv = new VOcItemFA();
            BeanUtils.copyProperties(iitem,vv);
            vvo.add(vv);
        }

        return vvo;
    }

    @Override
    public VOcItemFBI findById(int id) {
        CheckItem kk = checkItemMapper.findById(id);
        VOcItemFBI vv = new VOcItemFBI();
        if (kk != null) {
            BeanUtils.copyProperties(kk,vv);
        }
        return vv;
    }
}
